home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / or / or_valid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  7.5 KB  |  400 lines

  1. /* or_valid.c: check to see that OR tree matches with standard */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_valid.c,v 6.0 1991/12/18 20:23:08 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/or/RCS/or_valid.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_valid.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include "util.h"
  17. #include "or.h"
  18.  
  19. /* see table 10 in X.402 */
  20. /* forms of O/R address */
  21.  
  22. static int or_valid_term(), or_valid_post(), or_valid_mnem(), or_valid_none();
  23.  
  24. int or_valid_or (or)
  25. OR_ptr    or;
  26. {
  27.     switch (or_form_type(or)) {
  28.         case OR_FORM_TERM:
  29.         return or_valid_term(or);
  30.         case OR_FORM_POST:
  31.         return or_valid_post(or);
  32.         case OR_FORM_NUMR:
  33.         return or_valid_numr(or);
  34.         case OR_FORM_MNEM:
  35.         return or_valid_mnem(or);
  36.         default:
  37.         return or_valid_none(or);
  38.     }
  39. }
  40.  
  41. /*   */
  42. static int or_valid_term(or)
  43. OR_ptr    or;
  44. {
  45.     int    country, admd, x121, prmd, tid, dda;
  46.     country = admd = x121 = prmd = tid = dda = 0;
  47.  
  48. #define too_many(x)    { PP_LOG (LLOG_EXCEPTIONS, ("Too many %s components", (x))); return NOTOK; }
  49.  
  50.     while (or != NULLOR) {
  51.         switch (or->or_type) {
  52.             case OR_C:
  53.             if (country++ > 0)
  54.                 too_many("Country");
  55.             break;
  56.             case OR_ADMD:
  57.             if (admd++ > 0)
  58.                 too_many("ADMD");
  59.             break;
  60.             case OR_X121:
  61.             if (x121++ > 0)
  62.                 too_many ("X121");
  63.             break;
  64.             case OR_PRMD:
  65.             if (prmd++ > 0)
  66.                 too_many ("PRMD");
  67.             break;
  68.             case OR_TID:
  69.             if (tid++ > 0)
  70.                 too_many ("TID");
  71.             break;
  72.             case OR_DD:
  73.             if (dda++ > 3)
  74.                 too_many ("DD");
  75.             break;
  76.             default:
  77.             PP_LOG(LLOG_EXCEPTIONS,
  78.                    ("Invalid  component '%s=%s' for term form OR",
  79.                 or_type2name(or->or_type),
  80.                 or->or_value));
  81.             return NOTOK;
  82.         }
  83.         or = or -> or_next;
  84.     }
  85.  
  86.     if (x121 < 1) {
  87.         PP_LOG(LLOG_EXCEPTIONS,
  88.                ("Missing mandatory component '%s' for term form OR",
  89.             or_type2name(OR_X121)));
  90.         return NOTOK;
  91.     }
  92.     return OK;
  93. }
  94.  
  95. /* */
  96. static int or_valid_post(or)
  97. OR_ptr    or;
  98. {
  99.     int     country, admd, prmd, pdsname, pd_c, postcode,
  100.         or_comps, pd_comps, lpa, pdo_name, pdo_num, pd_o,
  101.         pd_pn, po_box, pra, street, upa_pa, upn;
  102.  
  103.     country = admd = prmd = pdsname = pd_c = postcode
  104.         = or_comps = pd_comps = lpa = pdo_name = pdo_num = pd_o
  105.                 = pd_pn = po_box = pra = street = upa_pa = upn = 0;
  106.  
  107.     while (or != NULLOR) {
  108.         switch (or->or_type) {
  109.             case OR_C:
  110.             country++;
  111.             break;
  112.             case OR_ADMD:
  113.             admd++;
  114.             break;
  115.             case OR_PRMD:
  116.             if (prmd++ > 0)
  117.                 too_many ("prmd");
  118.             break;
  119.             case OR_PDSNAME:
  120.             if (pdsname++ > 0)
  121.                 too_many ("pdsname");
  122.             break;
  123.             case OR_PD_C:
  124.             pd_c++;
  125.             break;
  126.             case OR_POSTCODE:
  127.             postcode++;
  128.             break;
  129.             case OR_OR_COMPS:
  130.             or_comps++;
  131.             break;
  132.             case OR_PD_COMPS:
  133.             pd_comps++;
  134.             break;
  135.             case OR_LPA:
  136.             lpa++;
  137.             break;
  138.             case OR_PDO_NAME:
  139.             pdo_name++;
  140.             break;
  141.             case OR_PDO_NUM:
  142.             pdo_num++;
  143.             break;
  144.             case OR_PD_O:
  145.             pd_o++;
  146.             break;
  147.             case OR_PD_PN:
  148.             pd_pn++;
  149.             break;
  150.             case OR_PO_BOX:
  151.             po_box++;
  152.             break;
  153.             case OR_PRA:
  154.             pra++;
  155.             break;
  156.             case OR_STREET:
  157.             street++;
  158.             break;
  159.             case OR_UPA_PA:
  160.             upa_pa++;
  161.             break;
  162.             case OR_UPN:
  163.             upn++;
  164.             break;
  165.             default:
  166.             PP_LOG(LLOG_EXCEPTIONS,
  167.                    ("Invalid  component '%s=%s' for postal form OR",
  168.                 or_type2name(or->or_type),
  169.                 or->or_value));
  170.             return NOTOK;
  171.         }
  172.         or = or -> or_next;
  173.     }
  174.  
  175.     if (country < 1) {
  176.         PP_LOG(LLOG_EXCEPTIONS,
  177.                ("Missing mandatory component '%s' for postal form OR",
  178.             or_type2name(OR_C)));
  179.         return NOTOK;
  180.     }
  181.  
  182.     if (admd < 1) {
  183.         PP_LOG(LLOG_EXCEPTIONS,
  184.                ("Missing mandatory component '%s' for postal form OR",
  185.             or_type2name(OR_ADMD)));
  186.         return NOTOK;
  187.     }
  188.  
  189.     if (pd_c < 1) {
  190.         PP_LOG(LLOG_EXCEPTIONS,
  191.                ("Missing mandatory component '%s' for postal form OR",
  192.             or_type2name(OR_PD_C)));
  193.         return NOTOK;
  194.     }
  195.  
  196.     if (postcode < 1) {
  197.         PP_LOG(LLOG_EXCEPTIONS,
  198.                ("Missing mandatory component '%s' for postal form OR",
  199.             or_type2name(OR_POSTCODE)));
  200.         return NOTOK;
  201.     }
  202.  
  203.     if (upa_pa == 1 &&
  204.         (or_comps > 0 || pd_comps > 0 || lpa > 0 || pdo_name > 0
  205.          || pdo_num > 0 || pd_o > 0 || pd_pn > 0 || po_box > 0
  206.          || pra > 0 || street > 0 || upn > 0)) {
  207.         PP_LOG(LLOG_EXCEPTIONS,
  208.                ("Illegal postal components in an unformatted postal OR"));
  209.         return NOTOK;
  210.     }
  211.  
  212.     return OK;
  213. }
  214.  
  215. /*   */
  216. static int or_valid_numr(or)
  217. OR_ptr    or;
  218. {
  219.     int    country, admd, prmd, uaid, dda;
  220.     country = admd = prmd = uaid = dda = 0;
  221.  
  222.     while (or != NULLOR) {
  223.         switch (or->or_type) {
  224.             case OR_C:
  225.             country++;
  226.             break;
  227.             case OR_ADMD:
  228.             admd++;
  229.             break;
  230.             case OR_PRMD:
  231.             if (prmd++ > 0)
  232.                 too_many ("PRMD");
  233.             break;
  234.             case OR_UAID:
  235.             uaid++;
  236.             break;
  237.             case OR_DD:
  238.             if (dda++ > 3)
  239.                 too_many ("DD");
  240.             break;
  241.             default:
  242.             PP_LOG(LLOG_EXCEPTIONS,
  243.                    ("Invalid  component '%s=%s' for numeric form OR",
  244.                 or_type2name(or->or_type),
  245.                 or->or_value));
  246.             return NOTOK;
  247.         }
  248.         or = or -> or_next;
  249.     }
  250.  
  251.     if (country < 1) {
  252.         PP_LOG(LLOG_EXCEPTIONS,
  253.                ("Missing mandatory component '%s' for numeric form OR",
  254.             or_type2name(OR_C)));
  255.         return NOTOK;
  256.     }
  257.  
  258.     if (admd < 1) {
  259.         PP_LOG(LLOG_EXCEPTIONS,
  260.                ("Missing mandatory component '%s' for numeric form OR",
  261.             or_type2name(OR_ADMD)));
  262.         return NOTOK;
  263.     }
  264.  
  265.     if (uaid < 1) {
  266.         PP_LOG(LLOG_EXCEPTIONS,
  267.                ("Missing mandatory component '%s' for numeric form OR",
  268.             or_type2name(OR_UAID)));
  269.         return NOTOK;
  270.     }
  271.  
  272.     return OK;
  273. }
  274.  
  275. /*   */
  276. static int or_valid_mnem(or)
  277. OR_ptr    or;
  278. {
  279.     int country, admd, prmd, cn, o, ou, s, g, i, gq, dda;
  280.     country = admd = prmd = cn = o = ou = s = g = i = gq = dda = 0;
  281.  
  282.     while (or != NULLOR) {
  283.         switch (or->or_type) {
  284.             case OR_C:
  285.             country++;
  286.             break;
  287.             case OR_ADMD:
  288.             admd++;
  289.             break;
  290.             case OR_CN:
  291.             if (cn++ > 0)
  292.                 too_many ("CN");
  293.             break;
  294.             case OR_PRMD:
  295.             if (prmd++ > 0)
  296.                 too_many ("PRMD");
  297.             break;
  298.             case OR_O:
  299.             if (o++ > 0)
  300.                 too_many ("O");
  301.             break;
  302.             case OR_OU:
  303.             case OR_OU1:
  304.             case OR_OU2:
  305.             case OR_OU3:
  306.             case OR_OU4:
  307.             if (ou++ > 3)
  308.                 too_many("OU");
  309.             break;
  310.             case OR_S:
  311.             s++;
  312.             break;
  313.             case OR_G:
  314.             g++;
  315.             break;
  316.             case OR_I:
  317.             i++;
  318.             break;
  319.             case OR_GQ:
  320.             gq++;
  321.             break;
  322.             case OR_DD:
  323.             if (dda++ > 3)
  324.                 too_many ("DD");
  325.             break;
  326.             default:
  327.             PP_LOG(LLOG_EXCEPTIONS,
  328.                    ("Invalid  component '%s=%s' for mnemonic form OR",
  329.                 or_type2name(or->or_type),
  330.                 or->or_value));
  331.             return NOTOK;
  332.         }
  333.         or = or -> or_next;
  334.     }
  335.  
  336.     if (country < 1) {
  337.         PP_LOG(LLOG_EXCEPTIONS,
  338.                ("Missing mandatory component '%s' for mnemonic form OR",
  339.             or_type2name(OR_C)));
  340.         return NOTOK;
  341.     }
  342.  
  343.     if (admd < 1) {
  344.         PP_LOG(LLOG_EXCEPTIONS,
  345.                ("Missing mandatory component '%s' for mnemonic form OR",
  346.             or_type2name(OR_ADMD)));
  347.         return NOTOK;
  348.     }
  349.  
  350.     if (s == 0 &&
  351.         (g > 0 || i > 0 || gq > 0)) {
  352.         PP_LOG(LLOG_EXCEPTIONS,
  353.                ("Missing mandatory surname component '%s' for personal name",
  354.             or_type2name(OR_S)));
  355.         return NOTOK;
  356.     }
  357.  
  358.     return OK;
  359. }
  360. /*   */
  361. static int or_valid_none(or)
  362. OR_ptr    or;
  363. {
  364.     int s, g, i, gq;
  365.     s = g = i = gq = 0;
  366.  
  367. /* just check personal name */
  368.     while (or != NULLOR) {
  369.         switch (or->or_type) {
  370.             case OR_S:
  371.             s++;
  372.             break;
  373.             case OR_G:
  374.             g++;
  375.             break;
  376.             case OR_I:
  377.             i++;
  378.             break;
  379.             case OR_GQ:
  380.             gq++;
  381.             break;
  382.             default:
  383.             /* don't know what form */
  384.             break;
  385.         }
  386.         or = or -> or_next;
  387.     }
  388.  
  389.     if (s == 0 &&
  390.         (g > 0 || i > 0 || gq > 0)) {
  391.         PP_LOG(LLOG_EXCEPTIONS,
  392.                ("Missing mandatory surname component '%s' for personal name",
  393.             or_type2name(OR_S)));
  394.         return NOTOK;
  395.     }
  396.  
  397.     return OK;
  398. }
  399. #undef too_many
  400.